//
//  GuideSymptomViewController.m
//  HarmonizePub
//
//  Created by Haven on 16/10/13.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "GuideSymptomViewController.h"
#import "IntelligentBody.h"
#import "Config.h"
#import "GuideSymptom.h"
#import "MJExtension.h"
#import "GuideDiagnoseViewController.h"

@interface GuideSymptomViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *titleLable;

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSArray *guideSymptomLists;
@end

@implementation GuideSymptomViewController
- (NSArray *)guideSymptomLists
{
    if (_guideSymptomLists == nil) {
        _guideSymptomLists = [[NSArray alloc] init];
    }
    return _guideSymptomLists;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLable.text = self.intelligentBody.bodyName;
    self.title =  [NSString stringWithFormat:@"%@自测", self.intelligentBody.bodyName];
    // 加载导诊列表
    [self loadGuideSymptomList];
}

// 加载导诊列表
- (void)loadGuideSymptomList
{
    NSDictionary *cookie = @{@"cookie" : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary *params = @{@"bodyId" : @(self.intelligentBody.id),
                             @"sex" : self.sex
                             };
    [HTTPSTool POSTRequestWithPath:XHGetGuideSymptom cookie: cookie params: params success:^(NSDictionary * _Nonnull JSON) {
        
        self.guideSymptomLists = [GuideSymptom mj_objectArrayWithKeyValuesArray:JSON[@"data"][@"list"]];
        
        [self.tableView reloadData];
    }];
}

#pragma mark -- UITableViewDelegate/UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.guideSymptomLists.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    GuideSymptom *guideSymptom = self.guideSymptomLists[indexPath.row];
    
    cell.textLabel.text = guideSymptom.symptomName;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GuideSymptom *guideSymptom = self.guideSymptomLists[indexPath.row];
    GuideDiagnoseViewController *guideDiagnoseViewController = [[GuideDiagnoseViewController alloc] init];
    guideDiagnoseViewController.guideSymptom = guideSymptom;
    guideDiagnoseViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:guideDiagnoseViewController animated:YES];

}
@end
